package edu.thu.studio.ormdesigner.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;

import edu.thu.studio.ormdesigner.editor.ORMMultiPageEditor;
import edu.thu.studio.ormdesigner.model.diagram.Diagram;
import edu.thu.studio.ormdesigner.model.diagram.DiagramSet;
import edu.thu.studio.ormdesigner.model.domain.DomainSet;
import edu.thu.studio.ormdesigner.model.orm.TableSet;
import edu.thu.studio.ormdesigner.model.orm.ViewSet;

@XStreamAlias("model")
public class ORMModel extends AbstractModel {
    
    private static final long serialVersionUID = 8729319470770699498L;
    
    @XStreamAlias("domains")
    private DomainSet domains = new DomainSet();
    
    @XStreamAlias("diagrams")
    private DiagramSet diagrams = new DiagramSet();
    
    @XStreamAlias("tables")
    private TableSet tableSet = new TableSet();
    
    @XStreamAlias("views")
    private ViewSet viewSet = new ViewSet();
    
    private double zoom = 1.0d;
    
    private int currentIndex = 0;
    
    public ORMModel() {
    }
    
    public double getZoom() {
        return zoom;
    }
    
    public void setZoom(double zoom) {
        this.zoom = zoom;
    }
    
    public DomainSet getDomains() {
        return domains;
    }
    
    public void setDomains(DomainSet domains) {
        this.domains = domains;
    }
    
    public TableSet getTableSet() {
        return tableSet;
    }
    
    public void setTableSet(TableSet tableSet) {
        this.tableSet = tableSet;
    }
    
    public ViewSet getViewSet() {
        return viewSet;
    }
    
    public void setViewSet(ViewSet viewSet) {
        this.viewSet = viewSet;
    }
    
    public DiagramSet getDiagrams() {
        return diagrams;
    }
    
    public void setDiagrams(DiagramSet diagrams) {
        this.diagrams = diagrams;
    }
    
    public void refreshOutline() {
        if (isUpdateable()) {
            this.firePropertyChange("refreshOutline", null, null);
        }
    }
    
    public Diagram getDiagram(int index) {
        return diagrams.getObjectList().get(index);
    }
    
    public int getCurrentIndex() {
        return currentIndex;
    }
    
    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
    }
    
    public Diagram getCurrrentDiagram(int index) {
        return this.diagrams.getObjectList().get(index);
    }
    
    public void checkAndInit() {
        if (this.diagrams.getObjectList().size() == 0) {
            Diagram newDiagram = new Diagram();
            newDiagram.checkAndInit();
            this.getDiagrams().addObject(newDiagram);
        }
        
    }
    
    public void setEditor(ORMMultiPageEditor ormMultiPageEditor) {
        this.diagrams.setEditor(ormMultiPageEditor);
    }
    
}
